/**
 * Copyright: Copyright (c)2011
 * Company: 易宝支付(YeePay)
 */
package net.loyintean.pearlshell.base.service.impl;

import java.io.IOException;
import java.util.ConcurrentModificationException;

/**
 * @author：jun.lin@yeepay.com
 * @since：2015年2月7日 下午7:55:21
 * @version:
 */
public class HttpServiceImplMultiThreadTester implements Runnable {

	private static final HttpServiceImpl service = new HttpServiceImpl();
	static {
		service.setUrl("http://localhost:8080/webtester/Echo");
	}

	HttpServiceImplMultiThreadTester(int n) {
		super();
		this.num = n;
	}

	private int num;

	public static void main(String[] args) {

		for (int i = 0; i < 100; i++) {

			Thread thread = new Thread(new HttpServiceImplMultiThreadTester(i));
			thread.setName("t_" + i);

			thread.start();
		}

	}

	/**
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {

		try {
			String init = Thread.currentThread().getName() + "===" + num;

			String echo = service.send(init);

			System.out.println(System.currentTimeMillis());

			if (!init.equals(echo)) {
				throw new ConcurrentModificationException("init=" + init
						+ ",echo=" + echo);
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
